import {I18Parse,CommonLang} from "@lowcode/jpaas-common-lib";
import ScriptLibLang from '../../../locales/lang/impl/share/isolateJs/ScriptLibLang';
let lang = ScriptLibLang.ScriptLib;
let i18n=function (langKey,text) {
    return I18Parse.getI18Val(lang,langKey, text)
}

let ScriptInsertAry=[
    {
        name:i18n('contextData','上下文数据'),
        children:[
            {
                name:i18n('contextUtil','引入上下文类'),
                script:"import com.redxun.common.utils.ContextUtil;"
            },
            {
                name:i18n('getCurrentUserId','获取当前用户ID'),
                script:"String userId=ContextUtil.getCurrentUserId();"
            },
            {
                name:i18n('getComanyId','获取当前公司ID'),
                script:"String userId=ContextUtil.getComanyId();"
            },
            {
                name:i18n('getCurrentUser','获取当前用户对象'),
                script:`//`+i18n('userObjectIs','用户对象为')+`:com.redxun.common.model.JPaasUser;
                    JPaasUser user=ContextUtil.getCurrentUser();`
            },
        ]
    },
    {
        name:i18n('logClass','日志类'),
        children:[
            {
                name:i18n('insert','插入')+"logUtil.debug",
                script:"logUtil.debug(\""+i18n('module','模块')+"\",\""+i18n('content','内容')+"\");"
            },
            {
                name:i18n('insert','插入')+"logUtil.info",
                script:"logUtil.info(\""+i18n('module','模块')+"\",\""+i18n('content','内容')+"\");"
            },
            {
                name:i18n('insert','插入')+"logUtil.warn",
                script:"logUtil.warn(\""+i18n('module','模块')+"\",\""+i18n('content','内容')+"\");"
            },
            {
                name:i18n('insert','插入')+"logUtil.error",
                script:"logUtil.error(\""+i18n('module','模块')+"\",\""+i18n('content','内容')+"\");"
            },
            {
                name:i18n('insert','插入')+"logger",
                script:"logger"
            },
        ]
    },
    {
        name:i18n('dbOperation','数据库操作'),
        children:[
            {
                name:i18n('import','导入')+"commonDao",
                script:"import com.redxun.common.utils.SpringUtil;\n" +
                    "import com.redxun.db.CommonDao;\n" +
                    "import com.redxun.common.base.entity.SqlModel;"
            },
            {
                name:i18n('getCommonDao','获取commonDao对象'),
                script:"CommonDao commonDao=SpringUtil.getBean(CommonDao.class);"
            },
            {
                name:i18n('sqlModel','构造SqlModel'),
                script:"SqlModel sqlModel=new SqlModel(sql);\n" +
                    "sqlModel.addParam(\"id\",1);"
            },
            {
                name:i18n('exeSqlSources','执行SQL使用数据源'),
                script:"//alias："+i18n('sourceAlias','数据源别名')+",sql:"+i18n('sqlStatement','sql语句')+"\n" +
                    "int execute(String alias,String sql)"
            },
            {
                name:i18n('executeSql','执行SQL'),
                script:"sql:"+i18n('sqlStatement','sql语句')+"\n" +
                    "int execute(String sql);"
            },
            {
                name:i18n('executeSqlParam','执行SQL(参数化)'),
                script:`String sql="insert into orders (ID_,NAME_,ALIAS_) values (#{id},#{name},#{alias});"
                    Map<String,Object> map=new HashMap<String, Object>();
                    map.put("id", "2");
                    map.put("name", "");
                    map.put("alias", "redxun");
                    //`+i18n('sqlStatement','sql语句')+`,params `+i18n('mapObj','map对象')+`
                    commonDao.execute(sql, map);`
            },
        ]
    },
    {
        name:i18n('toolClass','工具类'),
        children:[
            {
                name:i18n('import','导入')+"JSONObject",
                script:"import com.alibaba.fastjson.JSONObject;"
            },
            {
                name:i18n('objToString','将java对象转成字符串'),
                script:"String json=JSONObject.toJSONString(obj);"
            },
            {
                name:i18n('stringToJson','将字符串转成JSON'),
                script:"JSONObject jsonObject=JSONObject.parseObject(\"str\")"
            },
            {
                name:i18n('messageUtil','引入错误消息类'),
                script:`import com.redxun.common.utils.MessageUtil;`
            },
            {
                name:i18n('triggerException','抛出错误消息'),
                script:`MessageUtil.triggerException("`+i18n('triggerException','抛出错误消息')+`");`
            },
        ]
    },
];

export default  ScriptInsertAry;